'''
Created on Jun 28, 2012

@author: shashank
'''
#Defining a singleton class

class BiginersSinglton(object):
    """
    This is an implementation of a Singlton class from one of the Stack Overflow posts
    Not the best but I think we can improve this further.
    """
    _dict = dict()

    def __new__(cls):
        """
        This method must return the object unlike __init__ which return None.
        """
        if BiginersSinglton._dict.has_key('key'):
            return BiginersSinglton._dict['key']
        else:
            return super(BiginersSinglton, cls).__new__(cls)

    def __init__(self):
        BiginersSinglton._dict['key'] = self

if __name__ == '__main__':
    a1 = BiginersSinglton();print id(a1)
    a2 = BiginersSinglton();print id(a2)
    a3 = BiginersSinglton();print id(a3)
    